import requests
from bs4 import BeautifulSoup
import os

if __name__=="__main__":

    #获取所有的章节
    start_url='http://www.biqukan.com/1_1452/'
    r=requests.get(start_url)
    bf=BeautifulSoup(r.text,'html5lib')
    div=bf.find_all('div',class_="listmain")
    a_bf=BeautifulSoup(str(div).split('正文卷')[1],'html5lib')
    a=a_bf.find_all('a')
    server='http://www.biqukan.com/'
    urls=[]
    for i in a:
            urls.append(server+i.get('href'))   #存放链接
    for url in urls:
        r=requests.get(url)
        bf=BeautifulSoup(r.text,'html5lib')
        content=bf.find('div',id="content")
        f=open('d://武道宗师.txt','a+')

        f.write(content.text.replace('\xa0',' '))
        f.close()






